//
//  LGPhotoPickerCell.m
//  LGSanofiPatient
//
//  Created by 1234 on 2023/1/12.
//

#import "LGPhotoPickerCell.h"

@implementation LGPhotoPickerCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
//        self.clipsToBounds = NO;
//        self.contentView.clipsToBounds = NO;
//        self.deleteBtn.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.photoView];
        [self.contentView addSubview:self.deleteBtn];
        [self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.contentView).offset(viewPix(8));
            make.bottom.right.equalTo(self.contentView).offset(-viewPix(8));
        }];
        [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.photoView).offset(-viewPix(9));
            make.right.equalTo(self.photoView).offset(viewPix(12));
            make.width.height.equalTo(@(viewPix(30)));
        }];
    }
    return self;
}

-(void)setModel:(HXPhotoModel *)model{
    _model = model;
    self.deleteBtn.hidden = NO;
    if(model.thumbPhoto){
        self.photoView.image = model.thumbPhoto;
    }else if (model.previewPhoto){
        self.photoView.image = model.previewPhoto;
    }else if (model.imageURL){
        [self.photoView sd_setImageWithURL:model.imageURL placeholderImage:defaultDoctorPic];
//        self.deleteBtn.hidden = YES;
    }else{
        self.photoView.image = nil;
    }
}

-(UIImageView *)photoView{
    if(!_photoView){
        _photoView = [[UIImageView alloc]init];
        _photoView.contentMode = UIViewContentModeScaleAspectFill;
        _photoView.userInteractionEnabled = YES;
        _photoView.cornerRidus = 5;
    }
    return _photoView;
}

-(UIButton *)deleteBtn{
    if(!_deleteBtn){
        _deleteBtn = [UIButton buttonWithImage:@"上传图片-删除" selectImage:@"上传图片-删除"];
    }
    return _deleteBtn;
}
@end
